package cn.jwcat.controller;

import cn.jwcat.entity.Menu;
import cn.jwcat.entity.Staff;
import cn.jwcat.service.IMenuService;
import cn.jwcat.utils.JwtTokenUtil;
import cn.jwcat.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 菜单操作
 */
@Transactional
@RestController
@RequestMapping("/menu")
public class MenuController {
	@Resource
	IMenuService menuService;

	@Resource
	JwtTokenUtil jwtTokenUtil;

	@GetMapping
	@ApiOperation("根据用户角色获取菜单")
	public Result getMenuListByUserId(HttpServletRequest request) {
		Staff staff = jwtTokenUtil.getStaffFromRequest(request);
		List<Menu> menuListByUserId = menuService.getMenuListByUserId(staff.getStaffId());
		return Result.success(menuListByUserId);
	}
}
